package com.minew.beaconset.utils;

import android.content.Context;
import android.media.MediaPlayer;
import android.os.Vibrator;

import com.minew.beaconset.R;

public class CommonUtils {

    /**
     * 震动
     * @param context
     */
    public static void vibrator(Context context,boolean isInArea){
        Vibrator vibrator = (Vibrator)context.getSystemService(context.VIBRATOR_SERVICE);
        vibrator.vibrate(1000);
        if(isInArea){
            playVoice(context, R.raw.in);
        }else{
            playVoice(context, R.raw.out);
        }
    }

    /**
     * 播放语音
     * @param context
     * @param r
     */
    public static void playVoice(Context context,int r){
        MediaPlayer mediaPlayer = MediaPlayer.create(context,r);
        if(mediaPlayer.isPlaying()){
            mediaPlayer.stop();
        }
        mediaPlayer.start();
    }
}
